package cn.lingyangwl.agile.pay.pay.channel;

import cn.lingyangwl.framework.tool.core.exception.Assert;
import cn.lingyangwl.agile.pay.constant.IfCodeEnum;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author shenguangyang
 */
@Slf4j
public abstract class AbstractPayOrderQueryService implements IPayOrderQueryService {
    private static final Map<IfCodeEnum, IPayOrderQueryService> serviceMap = new ConcurrentHashMap<>();

    @PostConstruct
    public void abstractPayOrderQueryServiceInit() {
        IfCodeEnum ifCode = this.getIfCode();
        Assert.notNull(ifCode, "ifCode is null, class: " + this.getClass().getName());
        serviceMap.put(ifCode, this);
    }

    public static IPayOrderQueryService getService(IfCodeEnum ifCodeEnum) {
        Assert.notNull(ifCodeEnum, "ifCodeEnum is null");
        return serviceMap.get(ifCodeEnum);
    }

    public static IPayOrderQueryService getService(String ifCode) {
        return serviceMap.get(IfCodeEnum.ofByCode(ifCode));
    }
}
